import java.util.ArrayList;
import java.util.List;

//leetcode 1863 找出所有子集的异或总和再求和
public class SubsetXORSum {
    private int sum1;
    private int sum2;
    public int subsetXORSum(int[] nums) {
        sum1 = 0;
        sum2 = 0;
        dfs(nums, 0);
        return sum1;
    }

    private void dfs(int[] nums, int pos) {
        sum1 += sum2;
        for (int i = pos; i < nums.length; i++) {
            sum2 ^= nums[i];
            dfs(nums, i + 1);
            sum2 ^= nums[i];
        }
    }
}
